package com.suxin.plugin.intergration.manager.plugin;

import com.suxin.plugin.intergration.manager.finder.CompoundPluginDescriptorFinder;
import com.suxin.plugin.intergration.manager.finder.ManifestPluginDescriptorFinder;
import com.suxin.plugin.intergration.manager.finder.PluginDescriptorFinder;
import com.suxin.plugin.intergration.manager.finder.PropertiesPluginDescriptorFinder;
import com.suxin.plugin.intergration.manager.loader.CompoundPluginLoader;
import com.suxin.plugin.intergration.manager.loader.DefaultPluginLoader;
import com.suxin.plugin.intergration.manager.loader.JarPluginLoader;
import com.suxin.plugin.intergration.manager.loader.PluginLoader;
import com.suxin.plugin.intergration.manager.repository.CompoundPluginRepository;
import com.suxin.plugin.intergration.manager.repository.DefaultPluginRepository;
import com.suxin.plugin.intergration.manager.repository.JarPluginRepository;
import com.suxin.plugin.intergration.manager.repository.PluginRepository;

import java.nio.file.Path;

/**
 * @author Tang
 * @classname DefaultPluginManager
 * @description [  ]
 * @date 2022/6/26 23:20
 */
public class DefaultPluginManager extends AbstractPluginManager{

    public DefaultPluginManager(Path pluginRoot) {
        super(pluginRoot);
    }

    @Override
    public com.suxin.plugin.pf4j.PluginFactory createPluginFactory() {
        return new com.suxin.plugin.pf4j.DefaultPluginFactory();
    }

    @Override
    protected PluginDescriptorFinder createPluginDescriptorFinder() {
        return new CompoundPluginDescriptorFinder()
                .add(new PropertiesPluginDescriptorFinder())
                .add(new ManifestPluginDescriptorFinder())
                ;
    }


    @Override
    protected PluginLoader createPluginClassLoader() {
        return new CompoundPluginLoader()
                .add(new DefaultPluginLoader(this))
                .add(new JarPluginLoader())
                ;
    }

    @Override
    protected PluginRepository createPluginRepository() {
        return new CompoundPluginRepository()
                .add(new JarPluginRepository(getPluginRoot()))
                .add(new DefaultPluginRepository(getPluginRoot()))
                ;
    }

}